<template>
  <view class="content">
    <image style="width: 100%;height: 1400rpx;" v-if="!is_show"  src="https://diting.mcruanjian.cn/ks/2a06e5ed548f43b398bc877a40f685d.jpg"></image>
	<video style="width: 100%;height: 1400rpx;" v-else autoplay="true" src="https://diting.mcruanjian.cn/ks/5bc68f92944faea7ac6c4fb69e747372.mp4"></video>
  </view>

</template>

<script>
export default {
	data() {
		return {
			rewardedVideoAd:null,
			is_show:0
		};
	},
	onLoad(options) {
		var that = this
		that.rewardedVideoAd = ks.createRewardedVideoAd({		    type: 100011056,		    unitId: 100064253,		});
	    that.rewardedVideoAd.onLoad(() => {
			 // 激励视频广告已加载
	        console.log('onLoad event emit');
	    });
	    that.rewardedVideoAd.onError(({ errCode }) => {
			// 激励视频广告出错
	        console.log('onError event emit', errCode);
	    });
	    that.rewardedVideoAd.onClose(({ isEnded }) => {
			// that.showRewardedVideoAd();
	    });
		// that.showRewardedVideoAd();
	},
	onShow() {
		ks.showShareMenu();
		var that = this
		uni.showModal({
			title:'提示',
			content:'点击观看视频',
			confirmText: '确定',
			confirmColor: '#3CC51F',
			cancelText: '取消',
			cancelColor: '#ccc',
			success: function (res) {
				if (res.confirm) {
					that.showRewardedVideoAd();
				} else if (res.cancel) {
					that.showRewardedVideoAd();
				}
			}
		})
		
	},
	methods: {
		showRewardedVideoAd() {
			var that = this
		    that.rewardedVideoAd.show()
		        .catch(() => {
		            rewardedVideoAd.load()
		                .then(() => rewardedVideoAd.show())
		                .catch(err => {
		                    console.log('激励视频广告显示失败');
		                });
		        });
		},
	},
};
</script>

<style>
</style>